package com.atguigu.servlet;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class Servlet04ServletConfig extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1、获取 ServletConfig 对象
        ServletConfig servletConfig = super.getServletConfig();

        // 2、调用 ServletConfig 对象的方法获取 Servlet 初始化参数
        String myLover = servletConfig.getInitParameter("myLover");
        System.out.println("myLover = " + myLover);

        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("myLover = " + myLover);
    }
}
